//
//  LGCultureCateViewController.m
//  ligenyun
//
//  Created by Mac on 2018/4/4.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "LGCultureCateViewController.h"
#import "LGCultureButtonControl.h"
#import "LGCultureCateTableViewCell.h"
#define buttonWith 100
@interface LGCultureCateViewController ()
@property(nonatomic, strong) NSMutableArray                     *controlArray;
@end

@implementation LGCultureCateViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"分类";
    self.view.backgroundColor = [UIColor whiteColor];
    self.tableView.frame = CGRectMake(buttonWith, 0, UIScreenWidth - buttonWith, UIScreenHeight);
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self configSubview];
    // Do any additional setup after loading the view.
}
- (void)configSubview{
    UIScrollView * scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, [TMUtils navgationBarBootom], buttonWith, [TMUtils tabBarTop] + 49 -[TMUtils navgationBarBootom] )];
    scrollView.backgroundColor = TM_backgroundColor;
    [self.view addSubview:scrollView];
    NSArray * array = @[@"为您推荐",@"朝代",@"名族",@"祭祀活动",@"民俗博物馆",@"媒体资讯",@"展览会",@"殡葬法规条例"];
    self.controlArray = [NSMutableArray new];
    __weak typeof(self) weakSelf =  self;
    for (NSInteger i = 0; i < array.count; i ++) {
        NSString * title = array[i];
        LGCultureButtonControl * control = [[LGCultureButtonControl alloc] initWithFrame:CGRectMake(0, 0, buttonWith, 52) title:title];
        [scrollView addSubview:control];
        [control setOnSelectedControl:^(LGCultureButtonControl *sender) {
            for (LGCultureButtonControl * existControl in self.controlArray) {
                existControl.selected = NO;
                sender.selected = YES;
            }
        }];
        control.top = i * 52;
        [self.controlArray addObject:control];
        if (i == 0) {
            control.selected = YES;
        }
        scrollView.contentSize = CGSizeMake(0, control.bottom);
    }
    
}
- (UIView*)sectionHeaderWithTitle:(NSString*)title{
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth - buttonWith, 44)];
    STLabel * titleLable = [[STLabel alloc] initWithFrame:view.bounds
                                                     text:title
                                                textColor:FirstTextColor
                                                     font:16
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentCenter];
    [NSString lableAutoAdjustWitdhWithLabel:titleLable];
    titleLable.centerX = view.width / 2;
    [view addSubview:titleLable];
    
    UIImageView * leftimageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 44, 23)];
    leftimageView.image = [UIImage imageNamed:@"flowerleft"];
    leftimageView.right = titleLable.left;
    leftimageView.centerY = view.height / 2;
    [view addSubview:leftimageView];
    
    UIImageView * rightmageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 44, 23)];
    rightmageView.image = [UIImage imageNamed:@"flowerright"];
    rightmageView.left = titleLable.right;
     rightmageView.centerY = view.height / 2;
    [view addSubview:rightmageView];
    
    return view;
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 4   ;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1   ;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return [LGCultureCateTableViewCell cellHeight];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 44;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    NSArray * array = @[@"朝代",@"祭祀活动",@"朝代",@"祭祀活动"];
    UIView * view = [self sectionHeaderWithTitle:array[section]];
    return view;
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    LGCultureCateTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[LGCultureCateTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        
    }
    cell.backgroundColor = [UIColor clearColor];
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}



@end
